﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Prob_Distributions_ClassLibrary;

namespace tp4_montecarlo
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
            //Inicializo valores por defecto
            
            txtInversionInicial.Text = "3600";
            txtCantCuotas.Text = "12";
            txtCostoMercDoc.Text = "15";
            txtCostoMercUnit.Text = "1"+ Utils.coma + "25";
            txtPrecioVta.Text = "2" + Utils.coma + "8";
            txtMesesASimular.Text = "12";
            txtCantMercAComprar.Text = "360";
            txtPagoXMes.Text = "300";

            //cargar tabla de Demanda
            this.dgDemanda.Rows.Add(5);
            this.dgDemanda[0, 0].Value = "250";
            this.dgDemanda[0, 1].Value = "300";
            this.dgDemanda[0, 2].Value = "350";
            this.dgDemanda[0, 3].Value = "400";
            this.dgDemanda[0, 4].Value = "450";

            this.dgDemanda[1, 0].Value = "0"+Utils.coma+3;
            this.dgDemanda[1, 1].Value = "0" + Utils.coma + 25;
            this.dgDemanda[1, 2].Value = "0" + Utils.coma + 20;
            this.dgDemanda[1, 3].Value = "0" + Utils.coma + 15;
            this.dgDemanda[1, 4].Value = "0" + Utils.coma + 10;

            this.dgDemanda[2, 0].Value = "0 - 29";
            this.dgDemanda[2, 1].Value = "30 - 54";
            this.dgDemanda[2, 2].Value = "55 - 74";
            this.dgDemanda[2, 3].Value = "75 - 89";
            this.dgDemanda[2, 4].Value = "90 - 99";



        }

       private void validarNumeros(object sender, KeyPressEventArgs e)
       {
           if (e.KeyChar == (char)(Keys.Enter))
            {
                e.Handled = true;
                SendKeys.Send("{TAB}");
            }
            if (e.KeyChar == 8)//backspace
            {
                e.Handled = false;
                return;
            }

            bool IsDec = false;
            int nroDec = 0;

            for (int i = 0; i < ((System.Windows.Forms.TextBox) sender).Text.Length; i++)
            {
                if (((System.Windows.Forms.TextBox) sender).Text[i] == Utils.coma)
                    IsDec = true;

                if (IsDec && nroDec++ >= 2)
                {
                    e.Handled = true;
                    return;
                }
            }

            if (e.KeyChar >= 48 && e.KeyChar <= 57)
                e.Handled = false;
            else if (e.KeyChar == Utils.coma)//44 o 46
                e.Handled = (IsDec) ? true : false;
            else
                e.Handled = true;
        }

      

       private void btnCalcular_Click(object sender, EventArgs e)
       {
           this.Cursor = Cursors.WaitCursor;
           //Inicializo objeto Montecarlo
           
           Montecarlo montecarlo = new Montecarlo(decimal.Parse(txtPagoXMes.Text), decimal.Parse(txtCostoMercUnit.Text), decimal.Parse(txtPrecioVta.Text), decimal.Parse(txtCantMercAComprar.Text), decimal.Parse(txtMesesASimular.Text), dgMontecarlo);

           montecarlo.generarMontecarlo();
           this.tabControl1.SelectTab(1);

           this.Cursor = Cursors.Default;

                                 
        }

       private void txtCantCuotas_Validating(object sender, CancelEventArgs e)
       {
           txtPagoXMes.Text = ((double.Parse(txtInversionInicial.Text) / double.Parse(txtCantCuotas.Text))).ToString();
       }

       private void txtCostoMercDoc_Validating(object sender, CancelEventArgs e)
       {
           this.txtCostoMercUnit.Text = (double.Parse(this.txtCostoMercDoc.Text) / (double)12).ToString();

       }

       private void Form1_Load(object sender, EventArgs e)
       {

       }




        }           
             
}

